/** 
 * This file is part of WGA.
 * 
 * WGA is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * WGA is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with WGA.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Copyright 2010, 2011 Omar Andres Carmona Cortes, Roberto Leite de Moraes Rego Fihlo
 * 						omar@ifma.edu.br			robertoleite1@gmail.com
 */

package util;

import componentes.Individuo;
import componentes.Populacao;

public class Estatisticas {
	
	Populacao pop;

	public Estatisticas(Populacao pop){
		this.pop = pop;
	}
	
	public double media(){
		double media = 0;
		for (Individuo ind : this.pop.getIndividuos()){
			media += ind.getFitness();
		}
		return (media/this.pop.getTamanho());
	}
	
	public double desvioMedio(double valor, double media){
		return valor-media;
	}
	
	public double variancia(){
		double media = this.media();
		double variancia = 0;
		for (Individuo i : this.pop.getIndividuos()){
			variancia += Math.pow(this.desvioMedio(i.getFitness(), media), 2);
		}
		return (variancia/this.pop.getTamanho());
	}
	
	public double desvioPadrao(){
		return Math.sqrt(this.variancia());
	}

	public static void main (String[] args){
		Populacao pop = new Populacao(10, "");
		
		Estatisticas sttc = new Estatisticas(pop);
		System.out.println("media: "+sttc.media());
		System.out.println("variancia: "+sttc.variancia());
		System.out.println("desvio padrao: "+sttc.desvioPadrao());
		
		System.out.println();
		for (Individuo ind : pop.getIndividuos()){
			System.out.println(ind.getFitness());
		}
	}
}
